package com.doit.doit26;

import com.doit.beans.Emp;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import java.sql.SQLException;
import java.util.List;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

public class C3P0DateBasePool {

  public static void main(String[] args) throws SQLException {
    //1 获取数据库连接池对象  数据源
    //自动读取指定的配置文件（c3p0.properties）获取四个参数，创建N个连接对象
    ComboPooledDataSource dataSource = new ComboPooledDataSource();
    //2 使用工具类，查询数据，返回结果
    QueryRunner runner = new QueryRunner(dataSource);
    //3 执行语句并返回结果
    List<Emp> empList = runner.query("select * from t_emp where eid =2", new BeanListHandler<Emp>(Emp.class));
    //打印结果
    for (Emp emp : empList) {
      System.out.println(emp);
    }
  }

}
